#version 460
#define GLSLIFY 1

layout(points) in;
//layout(triangle_strip, max_vertices=128) out;
layout(line_strip, max_vertices=30) out;
//layout(points, max_vertices=24) out;

layout(std140, set=0, binding=0) uniform U_Matrix {
	mat4 mat_ProjecView;	
};

//layout(std140, set=1, binding=1) uniform mat4 Model_Matrix;
layout(std140, binding = 1) readonly buffer U1_Matrix {
	mat4 mat_Model[];
};

layout(std140, column_major, binding = 2) uniform U2_Matrix {
	//体素分辨率
	uvec4	m_Resolution;
	//世界大小
	vec4	m_WorldSize;
	//单元大小
	float	m_UnitInterval;
};

//====================== 顶点阶段输入数据 =====================
layout(location = 0) in vec4 vColor[];

in gl_PerVertex {
	vec4	gl_Position;
	float	gl_PointSize;
} gl_in[];

layout(location = 3) in VS_GS_VERTEX {
	uint	InstanceIndex;
	float	VBoxSize;
}vertex_in[];

//======================= 几何阶段输出数据 ========================
/*layout(location = 1) out VS_FS_VERTEX {
	vec4		gColor;
	flat ivec3	vUV_Offset;
	flat ivec2	vUV_Bound;
};*/

void main(void){
	// 位置  大小  对齐方式  深度
	mat4 mat = mat_Model[vertex_in[0].InstanceIndex];
	
	vec4 v = gl_in[0].gl_Position;
	float BoxSize = vertex_in[0].VBoxSize * 2;

	//底面;
	vec4 currentPoint = v;
	currentPoint.xyz -= BoxSize*0.5f;
	gl_Position = mat_ProjecView * mat * currentPoint;
	EmitVertex();

	currentPoint.x += BoxSize;
	gl_Position = mat_ProjecView * mat * currentPoint;
	EmitVertex();

	currentPoint.z += BoxSize;
	gl_Position = mat_ProjecView * mat * currentPoint;
	EmitVertex();

	currentPoint.x -= BoxSize;
	gl_Position = mat_ProjecView * mat * currentPoint;
	EmitVertex();

	currentPoint.z -= BoxSize;
	gl_Position = mat_ProjecView * mat * currentPoint;
	EmitVertex();
	EndPrimitive();

	//return;

	//顶面;
	currentPoint = v;
	currentPoint.xyz += BoxSize*0.5f;
	gl_Position = mat_ProjecView * mat * currentPoint;
	EmitVertex();

	currentPoint.z -= BoxSize;
	gl_Position = mat_ProjecView * mat * currentPoint;
	EmitVertex();

	currentPoint.x -= BoxSize;
	gl_Position = mat_ProjecView * mat * currentPoint;
	EmitVertex();

	currentPoint.z += BoxSize;
	gl_Position = mat_ProjecView * mat * currentPoint;
	EmitVertex();

	currentPoint.x += BoxSize;
	gl_Position = mat_ProjecView * mat * currentPoint;
	EmitVertex();
	EndPrimitive();

	//立面
	currentPoint = v;
	currentPoint.xyz += BoxSize*0.5f;
	gl_Position = mat_ProjecView * mat * currentPoint;
	EmitVertex();

	currentPoint.y -= BoxSize;
	gl_Position = mat_ProjecView * mat * currentPoint;
	EmitVertex();
	EndPrimitive();

	currentPoint.x -= BoxSize;
	gl_Position = mat_ProjecView * mat * currentPoint;
	EmitVertex();

	currentPoint.y += BoxSize;
	gl_Position = mat_ProjecView * mat * currentPoint;
	EmitVertex();
	EndPrimitive();

	currentPoint.z -= BoxSize;
	gl_Position = mat_ProjecView * mat * currentPoint;
	EmitVertex();

	currentPoint.y -= BoxSize;
	gl_Position = mat_ProjecView * mat * currentPoint;
	EmitVertex();
	EndPrimitive();

	currentPoint.x += BoxSize;
	gl_Position = mat_ProjecView * mat * currentPoint;
	EmitVertex();

	currentPoint.y += BoxSize;
	gl_Position = mat_ProjecView * mat * currentPoint;
	EmitVertex();
	EndPrimitive();
	
}

 